#include <zenilib.h>
#include "BrainSlug.h"
#include "Globals.h"

BrainSlug::BrainSlug(Vector2 pos_) :
	SpriteObject(pos_, Vector2(25, 25))
{
	addTexture("BrainSlug1");
	addTexture("BrainSlugEye");
	setColorFilter(0, "green");
	hostHealth = maxHostHealth = 70;
}

void BrainSlug::update(const float &timestep)
{
	if (!dead()){
		const float maxElapsed = 0.125f;
		if (moving && grounded()){
			textureChangeElapsedTime += timestep;
			if (textureChangeElapsedTime > maxElapsed){
				textureChangeElapsedTime = 0;
				textureNum = (textureNum + 1) % 2;
				textures[0] = "BrainSlug" + itos(textureNum + 1);
			}
		}
		else{
			textureChangeElapsedTime = maxElapsed;
			if (grounded()){
				textureNum = 0;
				textures[0] = "BrainSlug1";
			}
		}
	}
	else{
		vel.x = 0;
		rot = pi;
		deadTime += timestep;
		if (deadTime > 4.0f){
			gone = true;
		}
	}
	GameObject::update(timestep);
}